﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace MetalSoda.SQLScript
{

    public partial class DeployInstanceConfigurationsRuntimeTextTemplate
    {
        readonly ServerInfo Info;

        public DeployInstanceConfigurationsRuntimeTextTemplate(ServerInfo info)
        {
            if (info == null) { throw new ArgumentNullException("info"); }
            this.Info = info;
        }
    }

    public partial class DeleteContractRuntimeTextTemplate
    {
        readonly Contract Contract;

        public DeleteContractRuntimeTextTemplate(Contract contract)
        {
            if (contract == null) { throw new ArgumentNullException("contract"); }
            Contract = contract;
        }
    }

    public partial class AlterMessageTypeRuntimeTextTemplate
    {
        public readonly MessageType MessageType;

        public AlterMessageTypeRuntimeTextTemplate(MessageType messageType)
        {
            MessageType = messageType;
        }
    }

    public partial class CreateServiceRuntimeTextTemplate
    {
        readonly Service Service;
        readonly string ContractsCSV;

        public CreateServiceRuntimeTextTemplate(Service service)
        {
            if (service == null) { throw new ArgumentNullException("service"); }
            Service = service;
            var contractsCsv = new StringBuilder();
            foreach (var contract in Service.Contracts)
            {
                contractsCsv.AppendFormat("'{0}',", contract.Name);
            }
            ContractsCSV = Regex.Replace(contractsCsv.ToString(), @"(?s),\s*$", string.Empty, RegexOptions.RightToLeft);

        }        
    }

    public partial class CreateQueueRuntimeTextTemplate
    {
        readonly Queue Queue;
        public CreateQueueRuntimeTextTemplate(Queue queue)
        {
            Queue = queue;
        }
    }


    public partial class CreateMessageTypeRuntimeTextTemplate
    {
        readonly MessageType MessageType;
        public CreateMessageTypeRuntimeTextTemplate(MessageType messageType)
        {
            if (messageType == null) { throw new ArgumentNullException("messageType"); }
            this.MessageType = messageType;
        }

    }

    public partial class CreateContractRuntimeTextTemplate
    {
        readonly Contract Contract;
        readonly string MessageTypeCSVList;

        public CreateContractRuntimeTextTemplate(Contract contract)
        {
            if (contract == null) { throw new ArgumentNullException("contract"); }
            this.Contract = contract;
            var builder = new StringBuilder();
            foreach (var messageType in Contract.MessageTypes)
            {
                builder.AppendFormat("'{0}',", messageType.Name);
            }
            MessageTypeCSVList = Regex.Replace(builder.ToString(), @"(?s),\s*$", string.Empty, RegexOptions.RightToLeft);
        }
    }

    public partial class CreateRouteRuntimeTextTemplate
    {
        readonly Route Route;     

        public CreateRouteRuntimeTextTemplate(Route route)
        {
            if (route == null) { throw new ArgumentNullException("route"); }
            this.Route = route;
        }
    }

    public partial class EnableBrokerRuntimeTextTemplate
    {
        readonly string Database;
        public EnableBrokerRuntimeTextTemplate(string database)
        {
            if (database == null) { throw new ArgumentNullException("database"); }
            this.Database = database;
        }
    }


    public partial class CreateEndPointRuntimeTextTemplate
    {
        readonly ServerInfo Config;

        public CreateEndPointRuntimeTextTemplate(ServerInfo config)
        {
            if (config == null) { throw new ArgumentNullException("config"); }
            this.Config = config;
        }
    }

    public partial class SelectLoginRuntimeTextTemplate
    { }

    public partial class GrantConnectOnEndpointRuntimeTextTemplate
    {
        readonly string EndPointName;
        readonly string Login;

        public GrantConnectOnEndpointRuntimeTextTemplate(string endPointName,string login)
        {
            EndPointName = endPointName;
            Login = login;
        }

    }


    public partial class CreateDatabaseRuntimeTextTemplate
    {
        readonly string Database;

        public CreateDatabaseRuntimeTextTemplate(string database)
        {
            Database = database;
        }
    }
}
